
/*
;
$(function(){
	function loadContent(url){
		// for google analyst
//		 var _gaq = _gaq || [];
//		 _gaq.push(['_setAccount', 'UA-24328626-1']);
//		 _gaq.push(['_trackPageview']);
//	    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
//	    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
//	    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		
	    //add subfix of the url
		url = url + '.tiles';
		alert(url);
		$('#loading_content').show();
		$('.contentReplace').load(url, function(){
			$('#loading_content').hide();
			if(url != 'home.tiles'){
				$('.leftNav').show();
				$('.content').removeClass('contentDefault');
			}
				
			//window.location.href = window.location.protocol + "//"+ window.location.host + window.location.pathname+ "#" + url;
			// do min max icon
			$( ".portlet-header .ui-icon" ).click(function() {
				$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
				$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
			});
			
		});
	}
	
	$.history.init(function(url) {
		loadContent(url == "" ? "home" : url);
    });
	
});
*/

/*generate menu start*/
function builddata(data) {
    var source = [];
    var items = [];
    // build hierarchical source.
    for (var i = 0; i < data.length; i++) {
        var item = data[i];
        var label = item["name"];
        var parentid = item["pId"];
        var id = item["id"];
        var url = item["url"];

        if (items[parentid]) {
            var item = { parentid: parentid, label: label, url: url, item: item };
            if (!items[parentid].items) {
                items[parentid].items = [];
            }
            items[parentid].items[items[parentid].items.length] = item;
            items[id] = item;
        }
        else {
            items[id] = { parentid: parentid, label: label, url: url, item: item };
            source[id] = items[id];
        }
    }
    return source;
};
// build ul li
function buildUL (parent, items) {
    $.each(items, function () {
        if (this.label) {
            // create LI element and append it to the parent element.
        	//<li><a url="test_overview">Paging Test</a></li>
            var li = $("<li><a  href="+ this.url + ">" + this.label + "</a></li>");
            li.appendTo(parent);
            // if there are sub items, call the buildUL function.
            if (this.items && this.items.length > 0) {
                var ul = $("<ul></ul>");
                ul.appendTo(li);
                buildUL(ul, this.items);
            }
        }
    });
};
/*generate menu end*/